//
//  VRSafetyKnowledgeCell.m
//  VRFirefighting
//
//  Created by Veer on 2018/8/12.
//  Copyright © 2018年 Veer. All rights reserved.
//

#import "VRSafetyKnowledgeCell.h"

#import "VRSafetyKnowledgeModel.h"


@interface VRSafetyKnowledgeCell()

@property (nonatomic, assign) UIView *bottomLineView;
@property (nonatomic, weak) UIImageView *iconImgView;
@property (nonatomic, weak) UILabel *titleLbl;
@property (nonatomic, weak) UILabel *detailLbl;
@property (nonatomic, weak) UILabel *dateLbl;


@end

@implementation VRSafetyKnowledgeCell

+ (instancetype)cellWith:(UITableView *)tablevie
{
    static NSString *cellID = @"VRSafetyKnowledgeCell";
    
    VRSafetyKnowledgeCell *cell = [tablevie dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        
        cell = [[VRSafetyKnowledgeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.accessoryType = UITableViewCellAccessoryNone;
        // lieview
        [self setupSubView];
        
    }
    return self;
}


- (void)setupSubView
{
    
    UIView *selectedBgView = [[UIView alloc] init];
    selectedBgView.backgroundColor = RGB(238, 238, 238);
    self.selectedBackgroundView = selectedBgView;
    
    UIImageView *iconImgView = [[UIImageView alloc] init];
    iconImgView.layer.masksToBounds = YES;
    iconImgView.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:iconImgView];
    self.iconImgView = iconImgView;
    
    UILabel *titleLbl = [[UILabel alloc] init];
    titleLbl.textColor = RGB(51, 51, 51);
    titleLbl.font = VRFont(16);
    [self.contentView addSubview:titleLbl];
    self.titleLbl = titleLbl;
    
    UILabel *detailLbl = [[UILabel alloc] init];
    detailLbl.numberOfLines = 2;
    detailLbl.textColor = RGB(80, 80, 80);
    detailLbl.font = VRFont(14);
    [self.contentView addSubview:detailLbl];
    self.detailLbl = detailLbl;
    
    UILabel *dateLbl = [[UILabel alloc] init];
    dateLbl.textColor = RGB(100, 100, 100);
    dateLbl.font = VRFont(12);
    [self.contentView addSubview:dateLbl];
    self.dateLbl = dateLbl;
    
    UIView *bottomLineView = [[UIView alloc] init];
    bottomLineView.backgroundColor = RGB(228, 228, 228);
    [self.contentView addSubview:bottomLineView];
    self.bottomLineView = bottomLineView;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(self.contentView);
        make.width.mas_equalTo(146);
        make.height.mas_equalTo(96);
    }];
    
    [self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImgView.mas_right).offset(6);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(self.iconImgView);
    }];
    
    [self.detailLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLbl);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(self.titleLbl.mas_bottom).offset(6);
    }];
    
    [self.dateLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(self.iconImgView);
    }];
    
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(self.contentView);
        make.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
}


#pragma mark - setter && getter
- (void)setModel:(VRSafetyKnowledgeModel *)model
{
    _model = model;
    
    [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:model.fPicture]];
    self.titleLbl.text = model.fTitle;
    self.detailLbl.text = model.fContent;
    self.dateLbl.text = model.fTime;
}

@end
